package psn.kiko.controller.file;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import psn.kiko.pojo.R;
import psn.kiko.service.FileService;

/**
 * 2024/11/30 17:03
 */
@Controller
@RequestMapping("api/file")
@RequiredArgsConstructor
@Api(tags = "文件服务api")
public class FileController{
	private final FileService fileService;
	
	@ResponseBody
	@PostMapping("upload")
	@ApiOperation("文件上传api")
	public R<?> upload(@RequestParam("file") MultipartFile file){
		return fileService.uploadFile(file);
	}
	
	@GetMapping("/download/{fileName:.+}")
	@ApiOperation("文件下载api")
	public ResponseEntity<Resource> downloadFile(@PathVariable String fileName){
		return fileService.downloadFile(fileName);
	}
	
	@PostMapping("scan")
	@ApiOperation("文件信息扫描整理api")
	public R<?> scan(){
		return fileService.scanAndStore();
	}
}
